﻿<%@ page contentType="text/html; charset=utf-8"%>
<%@page language="java" pageEncoding="UTF-8"%>
<%@ page import="com.mysql.jdbc.Driver"%>
<%@ page import="java.sql.*"%>

<%
String userName="root";
String userpasswd="";
String dbName="a0713225307";

Object una=session.getAttribute("uname");
    request.setCharacterEncoding("UTF-8");
	Class.forName("com.mysql.jdbc.Driver").newInstance();
	String u="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userpasswd+"&useUnicode=true&characterEncoding=UTF-8";
    java.sql.Connection con=java.sql.DriverManager.getConnection(u,"root","");
	String sql="select * from message_db where uNam='"+una+"' order by mId desc";
	Statement statement=con.createStatement();
	ResultSet rs=statement.executeQuery(sql);

%>

<style>
.table-striped>tbody>tr:nth-child(odd){background-color:rgba(255,255,255,0.5)!important;}
 .odd {
  background-color:#FFF3EE;
 }
 .highlight {
  background-color:rgba(255,255,255,0.8);
}
</style>

<input type="hidden" id="current_page" />
<input type="hidden" id="show_per_page" />

<div style="height:750px;width:100%;">

<table id="content"class="table table-striped">

<tr style="width:100%;">
<th class="col-md-1">id</th>
<th class="col-md-3">发布时间</th>
<th class="col-md-6">信息</th>
<th class="col-md-2"></th>
</tr>

<tbody id="tb6"style="width:100%;">
 <%
while(rs.next()){

%>	

<tr style="width:100%;">
<td class="col-md-1">
<%
out.print(rs.getString(1));
%>
</td>
<td class="col-md-3">
<%
out.print(rs.getString(2));
%>
</td>

<td class="col-md-6">
<div style="width:200px;height:50px;overflow:hidden;">
<%
out.print(rs.getString(4));
%>
</div>
</td>
<td class="col-md-2" style="text-align:right;vertical-align:middle;">
<img src="../images/delete.png" style="width:20px;height:20px;visibility:hidden;"onclick="deleteM(event);" />
</td>
</tr>
<%
}
%>	
</tbody>
</table>
</div>

<div id="page_nav"></div>
<%
rs.close();
statement.close();
con.close();
%>
<script>
$(function(){
 

var show_per_page=10;
   var table =document.getElementById("tb6");
 var num_of_items = table.rows.length;
 var num_of_pages=Math.ceil(num_of_items/show_per_page);
 
 $('#current_page').val(0);
 $('#show_per_page').val(show_per_page);
 
 var nav_html='<a class="previous_link" onclick="previous()"style="background-color:rgba(255,255,255,0.8);color:black;margin:3px;padding:5px;border:white 1px solid;">上一页</a>';
 var current_link=0;
 while(num_of_pages>current_link){
 nav_html+='<a class="page_link" onclick="go_to_page('+current_link+')"longdesc="'+current_link+'"style="background-color:rgba(255,255,255,0.8);color:black;margin:3px;padding:5px;border:white 1px solid;">'+(current_link+1)+'</a>';
current_link++;
 }
 nav_html+='<a class="next_link" onclick="next()"style="background-color:rgba(255,255,255,0.8);color:black;margin:3px;padding:5px;border:white 1px solid;">下一页</a>';
 $('#page_nav').html(nav_html);
 $('#page_nav .page_link:first').addClass('active_page');

  var trs=$("#tb6 tr");
  $(trs).css("display","none");
//	for(var i=0;i<trs.length;i++){
//	trs[i].style.display="none";
//	}

	$(trs).slice(0,show_per_page).css("display","");
	
});

function previous(){
new_page=parseInt($('#current_page').val())-1;

if($('.active_page').prev('.page_link').length==true){
go_to_page(new_page);
}
}

function next(){
new_page=parseInt($('#current_page').val())+1;
if($('.active_page').next('.page_link').length==true){
go_to_page(new_page);
}
}

function go_to_page(page_num){
var show_per_page=parseInt($('#show_per_page').val());

start=page_num*show_per_page;
end=start+show_per_page;

var trs=$("#tb6 tr");
$(trs).css("display","none").slice(start,end).css("display","");

$('.page_link[longdesc=' + page_num +']').addClass('active_page').siblings('.active_page').removeClass('active_page');
	
	//update the current page input field
	$('#current_page').val(page_num);
}


var x4=$('#tb6 tr');
	for(var j=0;j<x4.length;j++){
		x4[j].onmouseover=function(){
			$(this).attr("class", "highlight");
			 var imgd=$(this).find('img');
	 imgd.css("visibility","visible");
		}
		
		
   x4[j].onmouseout = function() {
	   $(this).removeAttr("class");
	   var imgd=$(this).find('img');
	   imgd.css("visibility","hidden");
 // $(this).attr("class", "odd"); //鼠标离开时还原之前的class值
 //  }
	}
	}

function deleteM(e){
	e=e||window.event;
	e.target=e.target||e.srcElement;
	var p=$(e.target).parent().prev().prev().prev().text();
	var param="msId='"+p+"'";
	
	$.ajax({
		type:'POST',
		url:'deleteM.jsp',
		data:param,
		success:function(){
			window.location.href=window.location.href;
		}
	});
}	
</script>